package pm.devices;

import pm.config.Configuration;
import pm.devices.drives.Drive;
import pm.devices.drives.DrivesChecker;
import pm.devices.drives.DrivesListener;
import pm.devices.drives.DrivesUtil;

import java.io.File;
import java.math.BigDecimal;

public class DevicesModuleImpl implements DevicesModule, DrivesListener {

	private DevicesModuleListener devicesModuleListener;
	private Configuration configuration;

	public DevicesModuleImpl(final DevicesModuleListener devicesModuleListener, final Configuration configuration) {
		this.devicesModuleListener = devicesModuleListener;
		this.configuration = configuration;
		init();
	}

	private void init() {
		System.loadLibrary("jawt");
		System.loadLibrary(this.configuration.getNativeLibName());
		final DrivesChecker drivesChecker = new DrivesChecker(this.configuration.getDrivesUpdateTime());
		drivesChecker.addListener(this);
		new Thread(drivesChecker).start();
	}

	public Drive[] getDrives() {
		return DrivesUtil.getDrives();
	}

	public void ejectChange(final BigDecimal change) {
		//todo
	}

	public File scanToFile() {
		//todo
		return null;
	}

	public void drivesChanged(final Drive[] updatedDrives) {
		devicesModuleListener.drivesChanged(updatedDrives);
	}
}
